<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>绘制行政区划边界</title>
    <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.8&key=04f224f36ed45528fb3e414e04789003"></script>
    <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
    <script src="page/jquery-1.10.1.min.js"></script>

</head>
<body>
<div id="container"></div>
<script type="text/javascript">


    function aa(b){
        console.log(b);
        var polygons = [];
        //生成行政区划polygon
        var polygon = new AMap.Polygon({
            map: map,
            strokeWeight: 1,
            path: b,
            fillOpacity: 0.7,
            fillColor: '#CCF3FF',
            strokeColor: '#CC66CC'
        });
        polygons.push(polygon);
        map.setFitView();//地图自适应
    }


    function getlonlat() {
    var longlat;
        $.ajax({
            url:'http://localhost:8081/miaoxie/gaode/map/getlonlat.action?city=朝阳区',
//        url:'json.json',
            type:'GET',
            // async:true,    //或false,是否异步
            // data:{gz:gz,xl:xl,zw:zw},
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            success:function(data){
                longlat = data.lonlat;
                aa(longlat);

            }
        });

    }
    function addBeiJing() {
        //加载行政区划插件
        AMap.service('AMap.DistrictSearch', function() {
            var opts = {
                subdistrict: 1,   //返回下一级行政区
                extensions: 'all',  //返回行政区边界坐标组等具体信息
                level: 'city'  //查询行政级别为 市
            };
            //实例化DistrictSearch
            district = new AMap.DistrictSearch(opts);
            district.setLevel('district');
        });
    }
    $(function () {






        addBeiJing();
        getlonlat();
        // aa(longlat);

    })
    //初始化地图对象，加载地图
    var district, map = new AMap.Map("container", {
        resizeEnable: true,
        center: [116.397428, 39.90923],//地图中心点
        zoom: 10 //地图显示的缩放级别
    });
</script>
</body>
</html>